package com.jd.ty.web.util;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.util.StrutsTypeConverter;

public class LongConverter extends StrutsTypeConverter {
	private Logger logger = Logger.getLogger(LongConverter.class);

	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {

		if (Long.class == toClass) {

			try {
				return Long.parseLong(values[0]);
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}

		}
		return new Long(0);
	}

	@Override
	public String convertToString(Map context, Object o) {
		if (o != null) {
			return o.toString();
		} else {
			return "";
		}
	}

}
